<template>
    <div>
        <h1>会员等级添加</h1>
      <table class="table">
         <tbody>
            <tr>
            <td>等级名称</td>
            <td>
                <input type="text" v-model="data.levelName">
            </td>
        </tr>
        <tr>
            <td>权益名称</td>
            <td>
                <select v-model="data.quanyiid">
            <option value="0">请选择权益</option>
            <option v-for="e in XLK"  :value="e.id">{{ e.quanyiName }}</option>
        </select>
               
            </td>
        </tr>

        <tr>
            <td>状态</td>
            <td> <input type="checkbox" v-model="data.state" checked>选择为启用,未选择未禁用</td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="添加会员等级" @click="add"></td>
        </tr>
         </tbody>
      </table>
        
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';

onMounted(()=>{
    XLKS();
})

const router=useRouter();

const data = ref({
  "id": 0,
  "levelName": "",
  "state": true,
  "quanyiid": 0
})
 
var hh=ref(["免费洗车","免费早饭","八折","五折"])
var h=ref([])
//下拉框
const XLK=ref([{
    "id": 3,
    "quanyiName": "免费早饭",
    "qstate": true
  }])

const XLKS=()=>{
    axios.get("https://localhost:7065/api/LevelMember/GetQuan").then(res=>{
      XLK.value=res.data
    })
}


const add=()=>{ 

    axios.post("https://localhost:7065/api/LevelQuanyi/AddLevel",data.value).then(res=>{
          if(res.data>0)
          {
              alert("会员等级添加成功");
              router.push({path:"/lshow"})
          }
          else if(res.data==-1)
          {
             alert("会员名称重复")
             return;
          }
          else{
            alert("会员等级添加失败");
            return;
          }
    })
}

</script>

<style scoped>

</style>